package chapter67;

public class Student1 {
	private String name; //姓名
	private int sid; //学号
	private int age; //年龄
	
	public Student1(){
		
	}
	
	//重写student类构造方法
	public Student1(String name, int sid, int age){
		this.name = name;
		this.sid = sid;
		this.age = age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getSid() {
		return sid;
	}

	public void setSid(int sid) {
		this.sid = sid;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}
	
	/*重写object类的equals()方法
	比较规则：如果两个学生的名字和学号是一样，就认为是同一个学生
	obj：传过来的对象
	this：当前对象*/
	public boolean equals(Object obj){
		if (obj == this){
			return true;
		}
		if (!(obj instanceof Student1)){
			return false;
		}else {
			Student1 stu = (Student1)obj;
			if (stu.name.equals(this.name) && (stu.sid == this.sid)){
				return true;
			}
		}
		return false;
	}	
}
